package com.sgcc.ln.pmos.e_ln_order.presenter;

import com.sgcc.ln.pmos.common.base.BasePresenter;
import com.sgcc.ln.pmos.common.bean.BaseResponse;
import com.sgcc.ln.pmos.common.http.HttpInterConst;
import com.sgcc.ln.pmos.common.http.HttpRequestUtils;
import com.sgcc.ln.pmos.common.http.MvpNetCallback;
import com.sgcc.ln.pmos.common.utils.ListPageUtil;
import com.sgcc.ln.pmos.e_ln_order.bean.IndentBean;
import com.sgcc.ln.pmos.e_ln_order.contract.ContractContract;

import java.util.HashMap;
import java.util.Map;

import okhttp3.Call;

public class ContractPresenter extends BasePresenter<ContractContract.View> implements ContractContract.Presenter {

    @Override
    public void getContractList(int pageSize, boolean isLoading) {
        Map<String, Object> params = new HashMap<>();
        params.put("_t", System.currentTimeMillis());
        params.putAll(ListPageUtil.getPageInfo(pageSize));
        params.put("relCode", "");
        params.put("membersSdName", "");
        params.put("startTime", "");
        params.put("endTime", "");
        params.put("flag", "1");//订单传0 合约传1
        HttpRequestUtils.getInstance().request(params, HttpInterConst.ORDER_INDENT_LIST, new MvpNetCallback<IndentBean>(getView(), isLoading) {
            @Override
            public void onError(Call call, Exception e, int id) {
                super.onError(call, e, id);
                // 失败回调 判断界面是否销毁
                if (!isViewAttached()) {
                    return;
                }
                getView().queryFailed();
            }

            @Override
            public void onResponse(IndentBean response, int id) {
                super.onResponse(response, id);
                if (!isViewAttached()) {
                    return;
                }
                getView().querySuccess(response);
            }
        });
    }

    @Override
    public void relieveContract(String relationId) {
        Map<String, Object> params = new HashMap<>();
        params.put("_t", System.currentTimeMillis());
        params.put("relationId", relationId);
        HttpRequestUtils.getInstance().request(params, HttpInterConst.ORDER_RELIEVECONTRACT, new MvpNetCallback<BaseResponse>(getView(), true) {
            @Override
            public void onError(Call call, Exception e, int id) {
                super.onError(call, e, id);
                // 失败回调 判断界面是否销毁
                if (!isViewAttached()) {
                    return;
                }
                getView().relieveContractFailed();
            }

            @Override
            public void onResponse(BaseResponse response, int id) {
                super.onResponse(response, id);
                if (!isViewAttached()) {
                    return;
                }
                getView().relieveContractSuccess(response);
            }
        });
    }
}
